function diff = fgamA(z_ss,EconGrowthRate,InvGrowthRate,g_y,delta0,r_ss,alf,gammaG)
% diff = fgamA(z_ss,EconGrowthRate,InvGrowthRate,g_y,delta0,r_ss,alf,gammaG)
%
% Calculates the difference between the model-calculted economic growth
% rate and a data parameter (EconGrowthRate).
%
% A difference of 0 implies that the model-calculated and data economic
% growth rates are identical.
%
% Created 10/29/2014 by Todd Messer

%% Calculations
% Growth Rates
gammaAx = exp(InvGrowthRate/100 - z_ss);
gammaX = exp(InvGrowthRate/100);
gammaG = exp(gammaG);
gammaA = exp(z_ss);

% Test to make sure this holds (It should, but I wanted to be safe)
assert((gammaAx-gammaX/gammaA)<1e-6)

% Steady-state Values
rk_ss   = exp(r_ss)*gammaAx - (1-delta0);
i_k     = 1-(1-delta0)/(gammaA * gammaAx);
y_k     = rk_ss/alf*((gammaA*gammaAx)^(-1));
i_y     = i_k/y_k;
c_y     = 1-g_y-i_y;

% Difference
gammaANew = gammaA*sqrt((c_y + gammaA/gammaX*i_y + gammaG^(-1)*g_y)/(c_y + gammaX/gammaA*i_y + gammaG*g_y));
gammaQ = exp(EconGrowthRate/100); 
diff = gammaANew-gammaQ;

end

